package com.ujs.edu.medicine.dao;

import com.ujs.edu.medicine.dataobject.YunjiayiLike;
import java.util.List;

import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
@Mapper
public interface YunjiayiLikeMapper {
    @Delete({
        "delete from yunjiayi_like",
        "where likeId = #{likeid,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer likeid);

    /*通过UID删除*/
    @Delete({
            "delete from yunjiayi_like",
            "where userId = #{userId,jdbcType=INTEGER}"
    })
    int deleteByUID(Integer userId);

    @Insert({
        "insert into yunjiayi_like (likeId, userId, ",
        "postId, create_time, ",
        "modify_time)",
        "values (#{likeid,jdbcType=INTEGER}, #{userid,jdbcType=INTEGER}, ",
        "#{postid,jdbcType=INTEGER},now(), ",
        "now())"
    })
    int insert(YunjiayiLike record);

    @Select({
        "select",
        "likeId, userId, postId, create_time, modify_time",
        "from yunjiayi_like",
        "where likeId = #{likeid,jdbcType=INTEGER}"
    })
    @Results(id = "likeMap",value = {
        @Result(column="likeId", property="likeid", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="userId", property="userid", jdbcType=JdbcType.INTEGER),
        @Result(column="postId", property="postid", jdbcType=JdbcType.INTEGER),
        @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="modify_time", property="modifyTime", jdbcType=JdbcType.TIMESTAMP)
    })
    YunjiayiLike selectByPrimaryKey(Integer likeid);

    @Select({
        "select",
        "likeId, userId, postId, create_time, modify_time",
        "from yunjiayi_like"
    })
    @Results({
        @Result(column="likeId", property="likeid", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="userId", property="userid", jdbcType=JdbcType.INTEGER),
        @Result(column="postId", property="postid", jdbcType=JdbcType.INTEGER),
        @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="modify_time", property="modifyTime", jdbcType=JdbcType.TIMESTAMP)
    })
    List<YunjiayiLike> selectAll();

    /*通过UID和PostID查询点赞*/
    @Select("select * from yunjiayi_like where postId=#{postId} and userId=#{userId}")
    YunjiayiLike getLikeByUidpostId(@Param("postId")Integer postId,@Param("userId")Integer userId);

    /*通过postId统计点赞数量*/
    @Select("select count(*) from yunjiayi_like where postId=#{postId}")
    Integer countLikeNum(@Param("postId")Integer postId);

    /*通过postId统计点赞数量*/
    @Select("select count(*) from yunjiayi_like where userId=#{uId}")
    Integer countLikeNumByUId(@Param("uId")Integer uId);


    @Update({
        "update yunjiayi_like",
        "set userId = #{userid,jdbcType=INTEGER},",
          "postId = #{postid,jdbcType=INTEGER},",
          "create_time = now(),",
          "modify_time = now()",
        "where likeId = #{likeid,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(YunjiayiLike record);
}